﻿using HealthcareSystem.API.Write.Application.Command;
using HealthcareSystem.API.Write.Application.Command.ChronicDisease;
using HealthcareSystem.API.Write.Application.Command.ChronicSignCommad;
using HealthcareSystem.API.Write.Application.Command.ElementCommand;
using HealthcareSystem.API.Write.Application.Command.FollowUp.FollowUpCommand;
using HealthcareSystem.API.Write.Application.Command.EquipmentCommand;
using HealthcareSystem.API.Write.Application.Command.MetricsCommands;
using HealthcareSystem.API.Write.Application.Command.TeamCommand;
using HealthcareSystem.API.Write.APPLication.Commad.ChronicSignCommad;
using HealthcareSystem.API.Write.APPLication.Commad.KnowledgeCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WeekExam.PassPort.ErrorCode;
using HealthcareSystem.API.Write.Application.Command.Disease;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace HealthcareSystem.API.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagmentController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
       IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary> 
        ILogger<ManagmentController> logger;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        /// <param name="logger">日志</param>
      
        public ManagmentController(ILogger<ManagmentController> logger, IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="cmd">处理</param>
        /// <returns>返回方法</returns>
        [HttpPost]
        public async Task<ApiResult<int>> Register(RegisterCommand cmd)
        {
            try
            {
                logger.LogInformation("用户进行注册操作");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("用户信息注册出错!" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 居民建档新增
        /// </summary>
        /// <param name="cmd">处理</param>
        /// <returns>返回方法</returns>
        [HttpPost]
        public async Task<ApiResult<int>> RecordAdd(FilingCommand cmd)
        {
            try
            {
                logger.LogInformation("居民建档新增操作");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("新增居民建档出错!" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 新增慢性病签约
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回新增慢性病签约请求结果</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddCSign(AddCSignCommad request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 我的知识-新增处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">返回我的知识请求结果</param>
        [HttpPost]
        public async Task<ApiResult<int>> AddKnowlege(AddknowledgeCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 指标分类添加方法
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> MetricsClassAdd(MetricsClassCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 指标添加方法
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> MetricsAdd(MetricsCreatedCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 指标修改方法 
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<ApiResult<int>> MetricssUpdate(MetricsUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 指标逻辑删除方法
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpDelete]
        public async Task<ApiResult<int>> MetricssDelete(MetricsDeleteCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 元素添加处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<ApiResult<int>> ElementAdd(AddElementCommanad request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 元素修改处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<ApiResult<int>> ElementPut(PutElementCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 团队逻辑删除列
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpDelete]
        public async Task<ApiResult<int>> TeamDelete(DeleteTeamCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 团队修改状态（启用、停用）
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpDelete]
        public async Task<ApiResult<int>> TeamState(TeamStateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 团队添加方法
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateTeam(TeamCreatedCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 团队修改方法
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateTeam(UpdateTeamCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 设备添加请求方法
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddEquipment(EquipmentCreateCommand command)
        {
            return await mediator.Send(command);
        }


        /// <summary>
        /// 健康宣教新增
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> HealthEducationAdd(HealthEducationAddCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 表单富文本添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<ApiResult<int>> AddTextfield(AddFollowUpCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 设备删除功能
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpDelete]
        public async Task<ApiResult<int>> EquipmentTableDelete(DeleteEquipmentCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 设备修改方法
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<ApiResult<int>> EquipmentTableUpdate(UpdateEquipmentCommand command)
        {
            return await mediator.Send(command);    
        }

        /// <summary>
        /// 健康报告新增
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> HealthReportAdd(HealthReportAddCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 健康报告修改状态
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<ApiResult<int>> HealthReportUpdateStatu(HealthReportUpdateStatuCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 健康报告删除
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<ApiResult<int>> HealthReportDelete([FromQuery]HealthReportDeleteCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 健康宣教删除
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<ApiResult<int>> HealthEductionDelete([FromQuery] HealthEducationDeleteCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 病列添加处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddDisease(AddDiseaseCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 病例编辑处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<ApiResult<int>> PutDisease(PutDiseaseCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 病种添加处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<ApiResult<int>> AddListofdiseases(AddListofdiseasesCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 逻辑删除慢性病签约
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回逻辑删除慢性病签约请求结果</returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DelCsign([FromQuery] DelCSignCommad request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 更新签约信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回更新签约信息请求结果</returns>
        [HttpPut]
        public async Task<ApiResult<int>>UpCSign(UpCsignCommad request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 就诊信息添加处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> DiagnosisAdd(DiagnosisAddCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 饮食方案添加
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> DietAdd(DietAddCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
